<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-02-20 13:59:15
 * @Last Modified time: 2023-02-20 14:02:09
 */

namespace app\sys\controller\store;

use app\sys\controller\Base;
use think\facade\{
    App
};
use app\common\services\store\RefundAddressService;
/**
 * 商城-退货地址
 * Class RefundAddress 
 * @package app\sys\controller\store
 */
class RefundAddress extends Base
{
    /**
     * RefundAddress constructor.
     * @param App $app
     */
    public function __construct(App $app,RefundAddressService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    /**
     * 退货地址列表
     * @method(GET)
     */
    public function list()
    {
        $where = $this->request->getMore([
        ]);
        $this->success($this->service->getRefundAddressList($where));
    }

    /**
     * 退货地址数据
     * @noAuth(true)
     * @method(GET)
     */
    public function select()
    {
        $this->success($this->service->getRefundAddressSelect());
    }

    /**
     * 退货地址详细 
     * @noAuth(true)
     * @method(GET)
     */
    public function detail(){
        $this->success($this->service->getRefundAddressDetail($this->request->get('id')));
    }


    /**
     * 添加退货地址
     * @method(POST)
     */
    public function create()
    {
        $data = $this->request->postMore([
            'name',
            'phone',
            'detail',
        ]);
        if($this->service->save( $data)){
            $this->success('添加成功!');
        }
        $this->error('添加失败!');
    }

    /**
     * 编辑退货地址
     * @method(PUT)
     */
    public function update()
    {
        if (!$id = $this->request->param('id')) {
            $this->error('参数错误!');
        }
        $data = $this->request->postMore([
            'name',
            'phone',
            'detail',
        ]);
        if($this->service->update($id, $data)){
            $this->success('修改成功!');
        }
        $this->error('修改失败!');
    }

    /**
     * 删除退货地址
     * @method(DELETE)
     */
    public function delete()
    {
        if (!$id = $this->request->param('id')) {
            $this->error('参数错误!');
        }

        if ($this->service->delete((int)$id)) {
            $this->success('删除成功!');
        } 
        $this->error('删除失败!');
    }

}